home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dviselect / font.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-16  |  7.0 KB  |  224 lines

  1. /*
  2.  * Copyright (c) 1987 University of Maryland Department of Computer Science.
  3.  * All rights reserved.  Permission to copy for any purpose is hereby granted
  4.  * so long as this copyright notice remains intact.
  5.  */
  6.  
  7. /*
  8.  * Font file information, readers, etc.
  9.  */
  10.  
  11. #ifndef _CTEX_TYPES_
  12. #include "types.h"
  13. #endif
  14.  
  15. /*
  16.  * First, font independent information: per glyph info, and per font
  17.  * info.
  18.  */
  19. struct glyph {
  20.     short    g_flags;    /* see below */
  21.     /*
  22.      * The following cannot be used with GetRasterlessFont
  23.      */
  24.     short    g_rotation;    /* see below */
  25.     char    *g_raster;    /* raster, if known */
  26.     /*
  27.      * These, however, do come with rasterless fonts,
  28.      * even though they relate only to the raster.
  29.      */
  30.     i32    g_height;    /* height of bounding box */
  31.     i32    g_width;    /* width of bounding box */
  32.     i32    g_yorigin;    /* y origin (>= 0 -> within box) */
  33.     i32    g_xorigin;    /* x origin (>= 0 -> within box) */
  34.     /*
  35.      * This of course comes with every font.
  36.      */
  37.     i32    g_tfmwidth;    /* width in scaled points (not FIXes!) */
  38. #ifdef notyet    /* THESE NEED MORE THOUGHT */
  39.     i32    g_xescapement;    /* x escapement (`chardx') */
  40.     i32    g_yescapement;    /* y escapement (`chardy') */
  41. #endif
  42.     /*
  43.      * This is provided purely for DVI to device conversion programs.
  44.      */
  45.     int    g_pixwidth;    /* width in pixels */
  46.     /*
  47.      * Mainly for internal use, index is the glyph index within the
  48.      * font.  That is, f->f_gly[i]->g_index == i.
  49.      */
  50.     int    g_index;    /* character index */
  51.     /*
  52.      * g_details and g_integer are purely for the font reading
  53.      * subroutines to use however they will.  g_next makes lists
  54.      * of glyphs while the glyphs are free.
  55.      */
  56.     union {            /* various options */
  57.         char    *g_details;    /* details: arbitrary */
  58.         i32    g_integer;    /* 32 bit integer */
  59.         struct    glyph *g_next;    /* linked list */
  60.     } g_un;
  61. };
  62.  
  63. /*
  64.  * Glyph flags.
  65.  */
  66. #define    GF_VALID    0x0001    /* glyph is `real' */
  67. #define    GF_USR0        0x0100    /* reserved to user code */
  68. #define    GF_USR1        0x0200    /* reserved to user code */
  69. #define    GF_USR2        0x0400    /* reserved to user code */
  70. #define    GF_USR3        0x0800    /* reserved to user code */
  71.  
  72. /*
  73.  * Rotations are in quarter-pi steps, counterclockwise of course.
  74.  * This order must be maintained; see rotate.c.
  75.  */
  76. #define    ROT_NORM    0        /* no rotation: `normal' position */
  77. #define    ROT_LEFT    1        /* 1/4 turn counterclockwise */
  78. #define    ROT_DOWN    2        /* 1/2 turn, i.e., upside-down */
  79. #define    ROT_RIGHT    3        /* 3/4 turn ccw, or 1/4 turn cw */
  80.  
  81. struct font {
  82.     int    f_flags;    /* see below */
  83.     struct    fontops *f_ops;    /* operations */
  84.     /*
  85.      * f_details is provided for font reading subroutines.
  86.      * It is intended to be cast to a pointer to a structure
  87.      * that is allocated by those routines, and used to keep
  88.      * track of whatever information those routines need to
  89.      * determine glyph boxes and (if asked for) rasters.
  90.      */
  91.     char    *f_details;    /* type dependent stuff */
  92.     /*
  93.      * f_path is the full pathname to the font file, filled in
  94.      * by GetFont and GetRasterlessFont.  Note that since we
  95.      * hold on to the path until the font is freed, it should be
  96.      * possible to cache glyph accesses on memory-poor machines.
  97.      */
  98.     char    *f_path;    /* font file pathname */
  99.     /*
  100.      * f_dvimag and f_dvidsz are the magnification and design size
  101.      * values from the DVI file.  f_font and f_scaled correspond to
  102.      * TeX's idea of the proper name for the font (e.g., `cmr10',
  103.      * `cmbx10 scaled 1440').  (Note that f_scaled is just the
  104.      * ratio of f_dvimag and f_dvidsz; you could save a bit of memory
  105.      * by eliminating it and altering the routine Font_TeXName()).
  106.      * f_checksum should be set by the font reading routines to
  107.      * the font checksum.  If the value is nonzero, it will be
  108.      * compared to the checksum in the DVI file.
  109.      */
  110.     i32    f_dvimag;    /* magnification from DVI file */
  111.     i32    f_dvidsz;    /* design size from DVI file */
  112.     char    *f_font;    /* TeX's name for the font */
  113.     int    f_scaled;    /* the ratio of dvimag to dvidsz, x1000 */
  114.     i32    f_checksum;    /* font checksum, or 0 */
  115. #ifdef notyet    /* THESE NEED MORE THOUGHT */
  116.     i32    f_hppp;        /* horizontal pixels per point */
  117.     i32    f_vppp;        /* vertical pixels per point */
  118. #endif
  119.     /*
  120.      * f_lowch and f_highch bound the region in which f_gly
  121.      * indicies are valid.  Specificially, f_gly[i] may be
  122.      * read or written if and only if i is in the half-open
  123.      * interval [f_lowch..f_highch).  f_gly is an array of
  124.      * pointers to glyph structures.  The structures themselves
  125.      * are not allocated until requested.
  126.      *
  127.      * f_glybase is the actual return from malloc(), since it
  128.      * is theoretically possible for f_gly-f_lowch to become
  129.      * NULL.
  130.      */
  131.     int    f_lowch;    /* first character */
  132.     int    f_highch;    /* last character, plus 1 */
  133.     struct    glyph **f_gly;    /* glyphs */
  134.     struct    glyph **f_glybase;
  135. };
  136.  
  137. /*
  138.  * Font flags.
  139.  */
  140. #define    FF_RASTERS    0x0001    /* font has rasters */
  141. #define    FF_USR0        0x0100    /* reserved to user code */
  142. #define    FF_USR1        0x0200    /* reserved to user code */
  143. #define    FF_USR2        0x0400    /* reserved to user code */
  144. #define    FF_USR3        0x0800    /* reserved to user code */
  145.  
  146. /*
  147.  * Operations on fonts.
  148.  *
  149.  * The `fo_dpitomag' field is used as a multiplier for a desired
  150.  * resolution in dots per inch.  The result of the multiplication
  151.  * is converted to a font name by multipying by 1000.0 and rounding.
  152.  * The idea is that PXL files will have a multiplier of 5.0, and
  153.  * others will have a multiplier of 1.0.  This suffices for the
  154.  * present, at any rate; in the future, this field may be replaced
  155.  * with something more general.
  156.  *
  157.  * N.B.: more operations may be added as they are discovered to be
  158.  * useful.
  159.  */
  160. struct    fontops {
  161.     char    *fo_name;        /* name, e.g., "gf" */
  162.     double    fo_dpitomag;        /* multiplier */
  163.     int    (*fo_read)();        /* open and read the font itself */
  164.     int    (*fo_getgly)();        /* obtain specified glyphs (range) */
  165. #ifdef notdef
  166.     int    (*fo_freegly)();    /* release specified glyphs */
  167. #endif
  168.     int    (*fo_rasterise)();    /* rasterise specified glyphs */
  169.     int    (*fo_freefont)();    /* discard font (free details) */
  170.     struct    fontops *fo_next;    /* purely for font.c */
  171. };
  172.  
  173. /*
  174.  * Return a pointer to the glyph information for character `c' in
  175.  * font `f'.
  176.  */
  177. #define    GLYPH(f, c) \
  178.     ((c) < (f)->f_lowch || (c) >= (f)->f_highch ? (struct glyph *) 0 : \
  179.      ((f)->f_gly[c] ? (f)->f_gly[c] : GetGlyph(f, c)))
  180.  
  181. /*
  182.  * True iff glyph `g' is valid.  Useful for checking return values
  183.  * from GLYPH().
  184.  */
  185. #define    GVALID(g)    ((g) && ((g)->g_flags & GF_VALID))
  186.  
  187. /*
  188.  * True iff glyph g has a raster.
  189.  */
  190. #define    HASRASTER(g)    ((g)->g_height || (g)->g_width)
  191.  
  192. /*
  193.  * Return a pointer to the raster information for glyph `g' in font
  194.  * `f' at rotation `r'.
  195.  */
  196. #define    RASTER(g, f, r)    ((g)->g_rotation == (r) && (g)->g_raster ? \
  197.              (g)->g_raster : GetRaster(g, f, r))
  198.  
  199. /*
  200.  * Function types.
  201.  */
  202. struct    font *GetFont(), *GetRasterlessFont();
  203. struct    glyph *GetGlyph();
  204. char    *GetRaster();
  205. void    FreeFont();
  206. void    FreeGlyph();
  207. void    FreeRaster();
  208. char    *Font_TeXName();
  209. double    DMagFactor();        /* from magfactor.c */
  210.  
  211. /*
  212.  * Normally from stdio.h
  213.  */
  214. #ifndef NULL
  215. #define    NULL    0
  216. #endif
  217.  
  218. /*
  219.  * The following environment variable overrides the default font
  220.  * configuration file.  That default is used when fontinit() is not
  221.  * called, or is passed a null pointer.
  222.  */
  223. #define    CONFENV    "TEXFONTDESC"
  224.